package com.caizi.designpattern.singleton;

/**
 * 懒汉式
 * 
 * @author caizi
 * 
 */
public class LazySingleton {

    private static LazySingleton instance = null;

    private LazySingleton() {

    }

    public synchronized static LazySingleton getInstance() {
        if (null == instance) {
            instance = new LazySingleton();
        }
        return instance;
    }

    /**
     * 双重锁检查
     * 
     * @return
     */
    public static LazySingleton getInstanceTwo() {
        if (null == instance) {
            synchronized (LazySingleton.class) {
                if (null == instance) {
                    instance = new LazySingleton();
                }
            }
        }
        return instance;
    }
}
